<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/base.jsp"%>
<%@ include file="/module/taglibs.jsp"%>
<%@ include file="/module/nocache.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>班主任顶班申请</title>
<%@ include file="/module/js.jsp"%>
</head>
<body>
	<form action="#" name="Form" id="Form" method="post">
		<input type="hidden" name="idList" id="idList"/>
		<input type="hidden" id="bodyData" name="bodyData" value=""/>
	<%@ include file="/module/orderField.jsp"%>
		<table cellpadding="1" cellspacing="1" border="0">
		<c:if test="${_login_user_type==2}">
			<tr>
			
				<td><input type="button" id="btnQuery" value="查询"
					class="inputButton" /></td>
	
			    <kl:permission permisstionList="${permisstionList}" currentUser="${_login_console_user}" currentCatalogId="<%=CatalogUtils.getCatalogId(\"XGGL_BJXX_BZRDB\")%>" key="add">	
				<td><input type="button" id="btnAdd" value="添 加" 
					class="inputButton" /></td>
			       </kl:permission>	
			    <kl:permission permisstionList="${permisstionList}" currentUser="${_login_console_user}" currentCatalogId="<%=CatalogUtils.getCatalogId(\"XGGL_BJXX_BZRDB\")%>" key="delete">			
				<td><input type="button" id="btnDelete" value="删除"
					 class="inputButton"/></td>
			 	</kl:permission>	 
			    <td><input type="button" id="btnExport" value="导出"
					 class="inputButton"/></td>
			</tr>
			</c:if>
		</table>
		<table cellpadding="1" cellspacing="1">
			<tr>
			    <td>状态：</td>
				<td><select id="states" name="states" class="selectList">
						<option value="">全部</option>
						<option value="0">未提交</option>
						<option value="1">审核中</option>
						<option value="2">审核通过</option>
						<option value="3">审核退回</option>
				</select></td>&nbsp;&nbsp;
				<td>顶班人：</td>
				<td><input type="text" name="dbxm"  id="dbxm"  placeholder="请输入"   autocomplete="off"   class="inputText"/></td>&nbsp;&nbsp;
				<td>申请日期：从</td>
				<td><input name="applydate1" id="applydate1" placeholder="请输入"   autocomplete="off" 
									class="Wdate  text inputText2" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd'})"/>&nbsp;到
		           <input name="applydate2" id="applydate2" placeholder="请输入"   autocomplete="off"  
									class="Wdate  text inputText2" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd'})"/></td>							
			</tr>
		</table>
		
     <table id="dg"  style="width:100%;"
		data-options="pagination:true,collapsible:true,url:'${basePath}/bjxxClassWorkInstead/List',method:'post',remoteSort:true,striped:true">
		<thead>
			<tr>
				<th data-options="field:'dbid',checkbox:true,width:80,align:'left'"></th>
				<th data-options="field:'applydate',sortable:true,nowrap:true,width:400,align:'left',formatter:formatDate">申请日期</th>
				<th data-options="field:'states',nowrap:true,width:200,align:'left',sortable:true,formatter:formstates">状态</th>
				<th data-options="field:'dbxm',nowrap:true,width:500,align:'left',sortable:true">顶班人</th>
			<!-- 	<th data-options="field:'dbzgh',nowrap:true,width:160,align:'left',sortable:true">顶班人工号</th> -->
				<th data-options="field:'ksrq',nowrap:true,width:320,align:'left',sortable:true,formatter:formatDateks">开始日期</th>
				<th data-options="field:'jsrq',nowrap:true,width:320,align:'left',sortable:true,formatter:formatDatejs">结束日期</th>
			
			</tr>
		</thead>
	</table>
		

		<script type="text/javascript">
		
		  function formstates(value,row, index){
		    	if(value==0){
		    		 return  value="未提交";
		    	}else if(value==1){
		    		 return value="审核中";
		    	}else if(value==2){
		    		 return value="审核通过";
		    	}else if(value==3){
		    		return  value="审核退回";
		    	}
			}   
		  
			
		    function formatDate(value,row, index){
		    	if(value!=null){
		    		var date=new Date(value);
					var y = date.getFullYear();
					var m = date.getMonth()+ 1;
					var d = date.getDate();
					var h= date.getHours();       //获取当前小时数(0-23)
					var mm= date.getMinutes();     //获取当前分钟数(0-59)
					var s= date.getSeconds();     //获取当前秒数(0-59)
				 	var data = y +'-'+(m <10?('0'+ m):m)+'-'+(d <10?('0'+ d):d)+'';
					return "<a href='${basePath}/bjxxClassWorkInstead/details?id=" + row.dbid + "'>" + data + "</a>";
		    	}else{
		    		return "";
		    	}
			}
		    
		    function formatDateks(value,row){
		    	if(value!=null){
		    		var date=new Date(value);
					var y = date.getFullYear();
					var m = date.getMonth()+ 1;
					var d = date.getDate();
					var h= date.getHours();       //获取当前小时数(0-23)
					var mm= date.getMinutes();     //获取当前分钟数(0-59)
					var s= date.getSeconds();     //获取当前秒数(0-59)
					return y +'-'+(m <10?('0'+ m):m)+'-'+(d <10?('0'+ d):d)+'&nbsp;&nbsp;&nbsp;&nbsp;'+row.ksrqfw;
		    	}else{
		    		return "";
		    	}
			}
		    
		    
		    function formatDatejs(value,row){
		    	if(value!=null){
		    		var date=new Date(value);
					var y = date.getFullYear();
					var m = date.getMonth()+ 1;
					var d = date.getDate();
					var h= date.getHours();       //获取当前小时数(0-23)
					var mm= date.getMinutes();     //获取当前分钟数(0-59)
					var s= date.getSeconds();     //获取当前秒数(0-59)
					return y +'-'+(m <10?('0'+ m):m)+'-'+(d <10?('0'+ d):d)+'&nbsp;&nbsp;&nbsp;&nbsp;'+row.jsrqfw;
		    	}else{
		    		return "";
		    	}
			}
		    
		    
			$(document).ready(
							function() {
						
					         	$('#dg').datagrid({
								  /*  onSortColumn :function(sort,order){
								   var _sort=sort;
								   var _order=order;
								   var options=$('#dg').datagrid('getPager').data("pagination").options;
								   var page=options.pageNumber;
								   var pageSize=options.pageSize;
								   window.setTimeout(function(){
									   $.post("${basePath}/bjxxClassWorkInstead/List",{orderFlag:_order,orderField:_sort,dbxm: $('#dbxm').val(),
											states: $('#states').val(),
											applydate1: $('#applydate1').val(),
											applydate2: $('#applydate2').val()},
												function(data){
												  $('#dg').datagrid("loadData",data); 
											   });
											   },100);  
								   },
								   rowStyler: function(index,row){
								   }, */
								   
								   onClickRow: function (rowIndex, rowData) {
						                 $(this).datagrid('unselectRow', rowIndex);
						            },

								   
								     onLoadSuccess: function(data){//加载完毕后获取所有的checkbox遍历
									                 if (data.rows.length > 0) {
									                    //循环判断操作为新增的不能选择
									                    var checkbox = $("input[type='checkbox']");
									                    for (var i = 0; i < data.rows.length; i++) {
									                        //根据states让某些行不可选
									                        if (data.rows[i].states != 0&&data.rows[i].states != 3) {
										                             /*    if(data.rows[i].states != 1){ */
										                                       $(checkbox.get(i+1)).remove();
										                            	//$("input[type='checkbox']")[i+1].remove();
										                               // $('#dg').datagrid('deleteRow',i);//选择该行 
									                                  // $("input[type='checkbox']")[i + 1].disabled = true;
									                                  //$("input[type='checkbox']")[i].remove();
										                               /*    } */
									                        }
									                    }
									                }
												},
								  
								});
								//查询
								$('#btnQuery')
										.click(
												function() {
													$('#dg').datagrid('load',{
														dbxm: $('#dbxm').val(),
														states: $('#states').val(),
														applydate1: $('#applydate1').val(),
														applydate2: $('#applydate2').val()
													});
												});
								

								 $('#easyui-ck').click(function() {
								    var data = $("#dg").datagrid("getSelections");
				                    for (var i = 0; i < data.length; i++) {
				                        //根据states让某些行不可选
				                        if (data[i].states != 0 &&data[i].states != 3) {
					                             /*  if(data[i].states != 1){  */
					                            	//$("input[type='checkbox']")[i+1].remove();
					                                 $('#dg').datagrid('unselectRow',i);//选择该行 
					                                 $("#easyui-ck").attr('checked','checked'); 
				                                     // $("input[type='checkbox']")[i + 1].disabled = true;
				                                  /*    }  */
												   /* $('#dg').datagrid('unselectRow',i);//选择该行 
								                   $("#ccc").attr('checked','checked');  */
				                        }/* else if(data[i].states != 1 ){
												   if(data[i].states != 0){ 
							                         	//$("input[type='checkbox']")[i+1].remove();
							                            $('#dg').datagrid('unselectRow',i);//选择该行 
							                            $("#ccc").attr('checked','checked'); 
							                                  // $("input[type='checkbox']")[i + 1].disabled = true;
							                            } 
													  
				                         } */
				                    }
								}); 
								
							

								$('#btnAdd').click(function() {
									   window.location.href = "${basePath}/bjxxClassWorkInstead/addInInt";
								});

								
								$('#btnExport').on('click', function(){
									   layer.confirm("您确定要导出吗?", {icon: 3, title:'提示',skin:'layer-ext-moon'}, function(index){
										   var rows = $("#dg").datagrid("getRows");
										  // var bodyData = JSON.stringify(rows);  //转成json字符串
										    $("#bodyData").val(JSON.stringify(rows));
											    document.Form.action = "${basePath}/bjxxClassWorkInstead/export_bzr";
												document.Form.submit();
												layer.close(index);
					            		 });
									});
								
							
								
								$('#btnDelete').click(function() {
									               $("#idList").val("");
													var count = 0;
													var idList = new Array();
												    var sels = $("#dg").datagrid("getSelections");
											    	for(var i in sels){
											    		idList.push(sels[i].dbid);
											    		count++;
											    	}
													
													if (count == 0) {
														layer.alert("您至少选择一条删除记录信息", {icon: 3});
														return false;
													}else{
														  layer.confirm("您是否删除当前选中数据信息", {icon: 3, title:'提示',skin:'layer-ext-moon'}, function(index){
															    $("#idList").val(idList);
															    document.Form.action = "${basePath}/bjxxClassWorkInstead/delete";
																document.Form.submit();
														  },function(index){
																layer.close(index);
														  });
													}
												});
						     	});
			
			
			
						$('#btnUpdate').click(function() {
										    var count = 0;
											var id =null;
										    var sels = $("#dg").datagrid("getSelections");
									    	for(var i in sels){
									    		if (count == 1) {
													  layer.alert("只能允许选择一条编辑记录信息", {icon: 3});
													  return false;
												}
									    		id=sels[i].id;
									    		count++;
									    	}
											if (count == 0) {
												 layer.alert("请选择一条编辑记录信息", {icon: 3});
												 return false;
											}else{
												 window.location.href ="${basePath}/bjxxClassWorkInstead/details?id="+ id;
												
											}
						});
						
			 if("${msg}"!=""){
			       layer.alert("${msg}", {icon: 6});
			  } 
		</script>
	</form>
</body>
</html>
